<?php  
namespace app\admin\controller;
// use think\Controller;
class Carousel extends Base{
	public function banner_list(){
		$arr=db('banner')->order('`order` asc')->paginate(5);
		// halt($arr);
		return view('',['arr'=>$arr]);
	}
	public function banner_add(){
		return view();
	}
	public function banner_insert(){
		// halt($_POST);
		$file=request()->file('img');
		$info=$file->move(ROOT_PATH.'public'.'/static/uploads');
		if($info){
			$_POST['img']=$info->getSaveName();
		}else{
			echo $info->getError();	
		}
		$file2=request()->file('img_text');
		$info2=$file2->move(ROOT_PATH.'public'.'/static/uploads');
		if($info2){
			$_POST['img_text']=$info2->getSaveName();
		}else{
			echo $info2->getError();	
		}
		if(db('banner')->insert($_POST)){
			$this->success('添加成功','banner_list');
		}else{
			$this->error('添加失败','banner_list');
		}
	}
	public function banner_del($id){
		$arr=db('banner')->find($id);
		if(db('banner')->delete($id)){
			unlink(ROOT_PATH.'public'.'/static/uploads/'.$arr['img']);
			unlink(ROOT_PATH.'public'.'/static/uploads/'.$arr['img_text']);
			$this->success('删除成功','banner_list');
		}else{
			$this->error('删除失败','banner_list');
		}
	}
	public function banner_edit(){
		// halt(input());
		if(db('banner')->update($_POST)){
			$this->success('修改成功','banner_list');
		}else{
			$this->error('修改失败','banner_list');
		}
	}
}
?>